package com.cqeec.demo1;

import ch.qos.logback.core.LifeCycleManager;
import com.cqeec.demo1.controller.BookController;
import com.cqeec.demo1.dao.BookDao;
import com.cqeec.demo1.entity.Book;
import com.cqeec.demo1.service.BookService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

import java.util.Map;

@SpringBootApplication
@Import(LifeCycleManager.class)
//@ComponentScan(basePackages="com.cqeec.demo.controller")
public class DemoApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext ioc=SpringApplication.run(DemoApplication.class, args);
        Book book = ioc.getBean(Book.class);
        System.out.println(book);
        System.out.println("======容器创建完成======");
        //获取bookController层的组件
        BookController bean=ioc.getBean(BookController.class);
        System.out.println(bean);
        // 获取bookService层的组件
        BookService bookServiceBean = ioc.getBean(BookService.class);
        System.out.println(bookServiceBean);

        // 获取bookDao层的组件
        BookDao bookDaoBean = ioc.getBean(BookDao.class);
        System.out.println(bookDaoBean);


        //根据类型获取   ,----报错
        Book bean0=ioc.getBean(Book.class);
        //根据名字获取
        Book bean1=(Book)ioc.getBean("red");
        //根据名字+类型获取
        Book bean2=(Book)ioc.getBean("red",Book.class);
        //获取这个类型的所有组件
        Map<String,Book> bean3=ioc.getBeansOfType(Book.class);
    }
}